import os
import sys
import time

from selenium import webdriver
from selenium.webdriver.common.by import By
import pytest
from selenium.webdriver.support.wait import WebDriverWait  # 等待模块
from selenium.webdriver.support import expected_conditions as ec
from ..Data.Data import Data
class Invest_Operation:
    def driver(self):
        driver = webdriver.Chrome()
        driver.get("http://localhost:90/")
        driver.maximize_window()
        return driver

    def login(self, username, password, driver):
        driver.implicitly_wait(5)
        ele1 = (driver.find_element(By.XPATH, "//*[@id='username']"))
        ele1.send_keys(username)
        ele2 = (driver.find_element(By.XPATH, '//*[@id="password"]'))
        ele2 .send_keys(password)
        ele3 = (driver.find_element(By.XPATH, '// *[ @ id = "login_btn"]'))
        ele3.click()
        time.sleep(1)
        return driver
    def invest(self,driver,buyname,paypwd):
        driver.find_element(By.XPATH, '/html/body/div/div/header/nav/div/div/div').click()
        driver.find_element(By.XPATH, '//*[@id="leftbaraside"]/div[2]/nav/ul/li[2]/a').click()
        driver.find_element(By.XPATH, '//*[@id="leftbaraside"]/div[2]/nav/ul/li[2]/ul/li[1]/a').click()
        driver.find_element(By.CSS_SELECTOR, f'.buy_btn[buybtnname="{buyname}"]').click()
        driver.find_element(By.XPATH, '//*[@class="layui-layer-content"]/input[@name="password"]').send_keys(paypwd)
        driver.find_element(By.XPATH, '//a[text()="确定"]').click()

    def GetSuccessResult(self,sql):
        result=Data().select(sql)
        return result

    def assertResult(self,result,expect):
        if result == expect:
            print("通过！")
        else:
            print("不通过！")
        assert result==expect

